// // 创建响应式引用
const userInfo: Ref<DataItem | null> = ref(null); // 初始化为 null

// // 获取用户信息并更新响应式引用
// onMounted(async () => {
//   const userAccount = localStorage.getItem('userAccount');
//   console.log(userAccount)
//   if (userAccount) {
//     try {
//       const response: UserInfo = await getUserInfo(userAccount);
//       console.log(response)
//       userInfo.value = response;
//     } catch (error) {
//       console.error('Error fetching user info:', error);
//     }
//   }
// });

const dataSource: Ref<DataItem[]> = ref([
  {
    id: '1',
    username: 'admin',
    userAccount: 'admin123',
    avatarUrl: 'https://example.com/avatar1.jpg',
    gender: 'male',
    userPassword: 'adminpass',
    phone: '1234567890',
    email: '',
    userStatus: '',
    createTime: '',
    updateTime: '',
    isDelete: '',
    userRole: '',
  },
  {
    id: '2',
    username: 'user',
    userAccount: 'user123',
    avatarUrl: 'https://example.com/avatar2.jpg',
    gender: 'female',
    userPassword: 'userpass',
    phone: '0987654321',
    email: '',
    userStatus: '',
    createTime: '',
    updateTime: '',
    isDelete: '',
    userRole: '',
  },
]);

// import axios from 'axios';
// 获取数据并赋值
onMounted(async () => {
  try {
    // 从后端获取数据
    // const response = await axios.get<DataItem[]>('http://localhost:8088/users/all');

    // 将数据赋值给响应式引用
    dataSource.value = await getAllUsers();
    userInfo.value = dataSource.value.find(
      e => e.userAccount === localStorage.getItem('userAccount'),
    );
    console.log(userInfo);
  } catch (error) {
    console.error('Error fetching data:', error);
  }
});